﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;
using CardLogistics.Model.Ordering;

namespace CardLogistics.Web.MainPage.Ordering.Ordering_Cardinfo
{
    public partial class Detail : BasePage
    {
        private static readonly CardLogistics.DAL.Ordering.Ordering_CardInfoData DAL = new DAL.Ordering.Ordering_CardInfoData();
        private static readonly CardLogistics.DAL.Ordering.Ordering_DetailedData DetailDAL = new DAL.Ordering.Ordering_DetailedData();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void InitControl()
        {
            string _key = Request.QueryString["id"];
            WebUserControl_AppInfo1.InfoID = _key;
            WebUserControl_AppInfo1.UserID = LoggedUser.ID;
            if (!string.IsNullOrEmpty(_key))
            {
                Ordering_CardInfo sData = DAL.GetModel(_key);
                SetWebControls(this.Page, sData);
                ORDERDATA.Text = Convert.ToDateTime(sData.ORDERDATA).ToShortDateString();//订单日期
                GETDATA.Text = Convert.ToDateTime(sData.GETDATA).ToShortDateString();//到货日期

                DataTable dt = DetailDAL.GetInfoById(_key);//通过订单Id获取订单版面数量
                string detName = "";
                string detId = "";
                if (dt != null && dt.Rows.Count > 0)
                {
                    //foreach (DataRow dr in dt.Rows)
                    //{
                    //    detName += dr["FormatName"].ToString() + "[" + dr["FormatNumber"].ToString() + "];";
                    //    detId += dr["FormatType"].ToString() + "|" + dr["FormatNumber"].ToString() + ";";
                    //}
                    //CardNumberName.Value = detName.TrimEnd(';') + "  总数量:" + Convert.ToInt32(dt.Compute("sum(FormatNumber)", ""));//版面数量;
                    //hf_CardNumberId.Value = detId.TrimEnd(';');


                    int TotalFormatNumber = 0; //版面片数量
                    if (dt.Rows[0]["FormatNumber"] != DBNull.Value)//版面片数量
                    {
                        TotalFormatNumber = Convert.ToInt32(dt.Compute("sum(FormatNumber)", ""));
                    }
                    else
                        TotalFormatNumber = 0;

                    DataRow dr = dt.NewRow();
                    dr["FormatName"] = "合计";
                    dr["FormatNumber"] = TotalFormatNumber;
                    dt.Rows.Add(dr);
                    rptDetailList.DataSource = dt;
                    rptDetailList.DataBind();

                }
            }

        }
    }
}